<?
include_once('conn.php');
include_once('include/func.php');
include("admin_check.php") ;
if($admin[0][2]<>10 and $admin[0][2]<>8 and $admin[0][2]<>7){exit('<script>alert("您没有权限"); window.history.back(-1);</script>');}

if($_POST){
$express=htmlspecialchars($_POST[express], ENT_QUOTES);
$esn=htmlspecialchars($_POST[esn], ENT_QUOTES);
		$db->UPDATE("UPDATE `".tablepre."order` SET `express`='".$express."',`esn`='".$esn."',`express_time`='".datetime."',`situation`='2' WHERE (`oid`='".$_POST[oid]."')");
		header("Location: $nowpage?action=1&ok");
	exit;
	}
	
	if(isset($_GET[cancel])){
	$db->UPDATE("UPDATE `".tablepre."order` SET `situation`='1' WHERE (`oid`='".$_GET[oid]."')");
	
	$order_list = $db->select("SELECT score,price,uid FROM `".tablepre."order` where paid = 1 and situation = 1 and `oid` = '".$_GET[oid]."'");
	
	$db->UPDATE("UPDATE `".tablepre."user` SET advance = concat(advance + ".$order_list[0][1].") , salesvolume = concat(salesvolume - ".$order_list[0][1].") , score = concat(score - '".$order_list[0][0]."')  WHERE (`uid`='".$order_list[0][2]."')");
	echo 'dfdf';
	back_to_stock($_GET[oid],$order_list[0][2]);
	header("Location: $nowpage?action=1&ok");
	exit;	
	}
	
if(isset($_GET[refund])){
	$db->UPDATE("UPDATE `".tablepre."order` SET `situation`='4' WHERE (`oid`='".$_GET[oid]."')");
	$order_list = $db->select("SELECT score,price,uid FROM `".tablepre."order` where paid = 1 and situation = 4 and `oid` = '".$_GET[oid]."'");
	
	$db->UPDATE("UPDATE `".tablepre."user` SET advance = concat(advance + ".$order_list[0][1].") , salesvolume = concat(salesvolume - ".$order_list[0][1].") , score = concat(score - '".$order_list[0][0]."')  WHERE (`uid`='".$order_list[0][2]."')");
	header("Location: $nowpage?action=2&ok");
	exit;	
	}

if(isset($_GET[norefund])){
	$db->UPDATE("UPDATE `".tablepre."order` SET `situation`='2' WHERE (`oid`='".$_GET[oid]."')");
	header("Location: $nowpage?action=2&ok");
	exit;	
	}
?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo systemname;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
	<!-- jquery packed -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="js/dtree.js"></script>
	<!-- tableRowCheckboxToggle -->
    <script type="text/javascript"> 
    function fade() 
{ 
    //停留2秒后消失,在停留的时候,透明度为1.0什么都不做 
    $('<div id="add" class="quick-alert">操作成功</div>').insertAfter($("#example")).animate({opacity: 1.0}, 2000).fadeOut("slow",function(){ 
   //隐藏时把元素删除 
   $(this).remove(); 
}); 
} 
</script> 
<link href="js/facefiles/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="js/facefiles/facebox.js" type="text/javascript"></script>
<script src="js/jc_table.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox() 
	  
	  $("div#print_button").click(function(){
    $("div#myPrintArea").printArea();
});
    })
		////////
</script>


<style>
.j_td{border:#999 solid 1px;}
.iframe{ width:700px;}
</style>
</head>
<body <? echo isset($_GET[ok])?'onload="fade();"':''; ?>>
<div id="wrap">
<div id="main" class="clearfix">
<div id="side">
  </div>
  <div id="head"><? include_once('admin_head.php');?></div>
  <div id="left"><?
  include_once('admin_menu.php');
  ?></div>
  <div id="right">
<div id="example"> </div>
<div id="myPrintArea">
<? if($_GET[action]==1){ ?>
<img src="images/ttfjpg.php?t=需要处理订单&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  />
<table border="0" cellspacing="1" cellpadding="0" class="jc_table">
  <tr class="header">
    <td>订单编号</td>
    <td>会员</td>
    <td>支付方式</td>
    <td>    订单总额</td>
    <td>商品总数</td>
    <td>时间</td>
    <td>状态</td>
       <td>查看</td>
    <td>发货</td>
    <td>取消</td>
    <td>打印</td>
  </tr>
  
        <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where situation = 0 order by datetime desc");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><a href="?action=3&uid=<? echo $order_list[$i][1];?>"><? echo mamber($order_list[$i][1],1);?></a></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><? echo $order_list[$i][15]==0?'未支付':'已付款';?></td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >商品详情</a></td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >发货</a></td>
      <td><a href="?cancel&oid=<? echo $order_list[$i][0];?>" onclick="return confirm('注意！取消订单将退还<? echo unit($order_list[$i][18]);?> 和扣除<? echo $order_list[$i][17];?>积分，并归还商品到库存。')">取消订单</a></td>
      <td><a href="include/print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      
      </tr>

<? } ?>
  <tr>
    <td colspan="11" class="middle">已发货[最后三条记录]</td>
  </tr>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where paid = 1 and situation = 2 order by express_time desc limit 3");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td><td><a href="?action=3&uid=<? echo $order_list[$i][1];?>"><? echo mamber($order_list[$i][1],1);?></a></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td>已付款</td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >发货详情</a></td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >已经发货</a></td>
      <td>&nbsp;</td>
      <td><a href="include/print.php?action=order&oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      
      </tr>

<? } ?>

</table>
<? }elseif($_GET[action]==2){?>
  <img src="images/ttfjpg.php?t=退货订单&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  />
      
     <table border="0" cellspacing="1" cellpadding="0" class="jc_table">
  <tr class="header">
    <td>订单编号</td>
    <td>支付方式</td>
    <td>订单总额</td>
    <td>商品总数</td>
    <td>时间</td>
    <td>查看</td>
    <td>状态</td>
    <td>退货</td>
    <td>打印</td>
  </tr>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where paid = 1 and situation = 3 order by datetime desc");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td>已付款</td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >商品详情</a></td>
      <td><a href="?refund&oid=<? echo $order_list[$i][0];?>" onclick="return confirm('注意！退货的同时将退还<? echo unit($order_list[$i][18]);?> 和扣除<? echo $order_list[$i][17];?>积分。')">退货</a>  |  <a href="?norefund&oid=<? echo $order_list[$i][0];?>" onclick="return confirm('不予退货')">撤销</a></td>
      <td><a href="include/print.php?action=order&amp;oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      </tr>
      <? } ?>
          <tr>
      <td colspan="9" class="middle">退货成功</td>
      </tr>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where paid = 1 and situation = 4 order by datetime desc limit 3");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td>已付款</td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >商品详情</a></td>
      <td>退货成功</td>
      <td><a href="include/print.php?action=order&amp;oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      </tr>

<? } ?>
  </table>
  <? }elseif($_GET[action]==3){ ?>
<img src="images/ttfjpg.php?t=订单历史记录&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  />
      <form method="get" action="">
      <input type="hidden" name="action" value="3" />
      订单查询 [输入会员名]：<input type="text" name="membername" /><input type="submit" value="查询" />
      </form>
           <table border="0" cellspacing="1" cellpadding="0" class="jc_table">
  <tr class="header">
    <td>订单编号</td>
    <td>会员</td>
    <td>支付方式</td>
    <td>订单总额</td>
    <td>商品总数</td>
    <td>时间</td>
    <td>状态</td>
    <td>查看</td>
    <td>打印</td>
  </tr>
  <? if($_GET[uid]<>null){?>
    <tr>
    <td colspan="9" style="border-bottom:#999 dotted 1px;"><a href="?action=3">查看全部会员订单</a></td>
    </tr>
    <? }?>
      <? 
	  if($_GET[membername]==null){
		  $uid_get=htmlspecialchars($_GET[uid], ENT_QUOTES);
		  $u_oredr_get=$_GET[uid]<>null?'where uid = '.$uid_get:'';
		  $order_list = $db->select("SELECT * FROM `".tablepre."order` ".$u_oredr_get." order by datetime desc");
		  }elseif($_GET[membername]<>null){
			  $membername_get=htmlspecialchars($_GET[membername], ENT_QUOTES);
			  $member_check = $db->select("SELECT uid FROM `".tablepre."user` where id = '".$membername_get."'");
			  if($member_check[0][0]==null){
				  exit('<script>alert("没有此用户"); window.history.back(-1);</script>');
				  }
				  $u_oredr_get=$member_check[0][0]<>null?'where uid = '.$member_check[0][0]:'';
			  $order_list = $db->select("SELECT * FROM `".tablepre."order` ".$u_oredr_get." order by datetime desc");
			  if($order_list[0][0]==null){
				  exit('<script>alert("此用户没有订单"); window.history.back(-1);</script>');
				  }
			  }
	  
	  
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><a href="?action=3&uid=<? echo $order_list[$i][1];?>"><? echo mamber($order_list[$i][1],1);?></a></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td><? echo $order_list[$i][15]==0?'未支付':'已付款';?></td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >商品详情</a></td>
      <td><a href="include/print.php?action=order&amp;oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      
      </tr>

<? } ?>
   


  </table><? }elseif($_GET[action]==4){ ?>
   
<img src="images/ttfjpg.php?t=订单历史记录[最后20条记录]&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  />
     
                 <table border="0" cellspacing="1" cellpadding="0" class="jc_table">
  <tr class="header">
    <td>订单编号</td>
    <td>会员</td>
    <td>支付方式</td>
    <td>订单总额</td>
    <td>商品总数</td>
    <td>时间</td>
    <td>状态</td>
    <td>查看</td>
    <td>打印</td>
  </tr>
      <? $order_list = $db->select("SELECT * FROM `".tablepre."order` where situation = 1 order by datetime desc limit 20");
	  for($i=0;$i<count($order_list);$i++){ 
	  ?>
    <tr class="t<? echo $i%2==0?1:2;?>">
      <td><? echo $order_list[$i][4];?></td>
      <td><a href="admin_user.php?uid=<? echo $order_list[$i][1];?>"><? echo mamber($order_list[$i][1],1);?></a></td>
      <td><? echo $order_list[$i][14];?></td>
      <td><? echo unit(order_total(1,$order_list[$i][0]));?></td>
      <td><? echo order_total(2,$order_list[$i][0]);?></td>
      <td><? echo substr($order_list[$i][11],0,-8);?></td>
      <td>已作废</td>
      <td><a href="include/check_order.php?oid=<? echo $order_list[$i][0];?>" rel="facebox[.iframe]" >商品详情</a></td>
      <td><a href="include/print.php?action=order&amp;oid=<? echo $order_list[$i][0];?>" target="_blank"><img src="images/print2.gif" /></a></td>
      
      </tr>

<? } ?>
   


  </table><? } ?></div>
<div id="print_button" style="width:32px; height:32px;"><a href="javascript:void(0);"><img src="images/print.png" /></a></div> 
</div>
  </div>
</div>

<div id="footer">
<?
include_once('fooder.php');
?>
</div>
</BODY>
</HTML>
